package com.walsai.pcsys.web.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.walsai.pcsys.core.model.User;

public class LoginValidator implements Validator {

	@Override
	public boolean supports(Class clazz) {
		return clazz.equals(User.class);
	}

	@Override
	public void validate(Object o, Errors errors) {
		User u = (User) o;
		if(u.getUsername().trim().length() < 6){
			errors.rejectValue("username", "error.invalid.username", "User name must be more than 6 characters.");
		}
		if(u.getPassword().length() < 8){
			errors.rejectValue("password", "error.password.username", "Password must be more than 8 chracters length.");
		}
	}

}
